﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using Ylh.IDAL;
using Ylh.FactoryDAL;

namespace Ylh.BLL
{
    public class ComRoleBLL
    {
        private string ConStr = string.Empty;

        public ComRoleBLL(string ConStr)
        {
            this.ConStr = ConStr;
        }


        /// <summary>
        /// 根据角色编号获取当前的角色信息
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="RoleID">角色编号</param>
        /// <returns></returns>
        public List<string> GetCompetenceByRoleID(string RoleID)
        {
            Ylh.IDAL.IComRole ICr = Ylh.FactoryDAL.DataAccess.CreateIComRole();

            DataTable dt = ICr.GetCompetenceByRoleID(ConStr, RoleID);


            List<string> li = new List<string>();
            foreach (DataRow dr in dt.Rows)
            {
                li.Add(dr["CompetenceID"].ToString());
            }

            return li;
        }


        public bool InserComByRold(string[] Coms, string RoleID)
        {
            try
            {
                Ylh.IDAL.IComRole ICr = Ylh.FactoryDAL.DataAccess.CreateIComRole();
                ICr.DeleteComByRole(ConStr, RoleID);


                foreach (string str in Coms)
                {
                    ICr.InsertCom(ConStr, RoleID, str);
                }

                return true;

            }
            catch
            {
                return false;
                throw;
            }
        }
    }
}
